package com.dlyk.service.impl;

import com.dlyk.constant.Constants;
import com.dlyk.mapper.DicTypeMapper;
import com.dlyk.model.DicType;
import com.dlyk.service.DicTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DicTypeServiceImpl implements DicTypeService {

    @Resource
    private DicTypeMapper dicTypeMapper;

    /**
     * 查询所有字典数据
     */
    @Override
    public List<DicType> loadAllDicData() {
        return dicTypeMapper.selectAllDicData();
    }

    /**
     * 查询字典类型列表（分页查询）
     */
    @Override
    public PageInfo<DicType> getDicTypeListByPage(Integer current) {

        // 1、设置PageHelper
        PageHelper.startPage(current, Constants.PAGE_SIZE);

        // 2、查询
        List<DicType> dicTypeList = dicTypeMapper.selectDicTypeList();

        // 3、封装分页数据到PageInfo
        PageInfo<DicType> dicTypePageInfo = new PageInfo<>(dicTypeList);

        return dicTypePageInfo;
    }

    /**
     * 录入字典类型
     */
    @Override
    public int addDicType(DicType dicType) {
        return dicTypeMapper.insertSelective(dicType);
    }

    /**
     * 编辑字典类型
     */
    @Override
    public int editDicType(DicType dicType) {
        return dicTypeMapper.updateByPrimaryKeySelective(dicType);
    }

    /**
     * 删除字典类型
     */
    @Override
    public int removeDicTypeById(Integer id) {
        return dicTypeMapper.deleteByPrimaryKey(id);
    }

    /**
     * 查询所有字典类型（下拉选项）
     */
    @Override
    public List<DicType> getAllDicType() {
        return dicTypeMapper.selectDicTypeList();
    }

}

